package member.service;

import java.sql.SQLException;

import library.domain.Member;
import member.dao.MemberDAO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MemberService {
	
	private MemberDAO dao;
	@Autowired
	public MemberService(MemberDAO dao){
		this.dao = dao;
	}
	
	//Id 중복 검사
	public boolean idCheck(String id) throws SQLException{
		Member m = dao.selectMemberById(id); 
		//id로 조회한 회원이 있으면 (m != null), 중복
		if(m != null){
			return false;
		}
		return true;
	}
	
	//회원등록
	public void insertMember(Member member) throws SQLException{
		dao.insertMember(member);
	}
	//로그인
	public Member loginMember(String id, String password) throws SQLException{
		Member m = dao.selectMemberById(id);
		//id 일치, pw 불일치
		if(m != null){ //일치하는 id가 있으면, pw 일치여부 확인
			if(password.equals(m.getMemberPassword())){//pw가 일치하면, 로그인 승인
				return m;
			}else{
				return null;
			}
		}
		//id 불일치
		return null;
	}
	
}
